package com.training.admin.entity.search;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 *
 * @author Rockett
 *
 */
public class TrainerSearch implements QueryBuilder {

    /** 名称 */
    private String name;
    
    /** 类型 */
    private String trainerType;
    /** 级别 */
    private String trainerLevel;
    /** 是否认证 */
    private  String certified;

    private QueryFilter filter;
    
    private QueryOrder order;

    
    /**
     * The default constructor
     */
    public TrainerSearch() {
        order = new QueryOrder();
    }
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
    	
        if (filter == null || refresh) {
        	
            filter = new QueryFilter().addLike("name", name)
            							.addLike("trainerLevel", trainerLevel)
                                      .addLike("trainerType", trainerType);
            if("0".equals(certified)){
            	filter.addEquals("certified", false);
            }else if("1".equals(certified)){
            	filter.addEquals("certified", true);
            }
            
        }
        
        return filter;
        
    }
    
 
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM Trainer Where disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}


    /**
	 * @return the trainerType
	 */
	public String getTrainerType() {
		return trainerType;
	}
	/**
	 * @param trainerType the trainerType to set
	 */
	public void setTrainerType(String trainerType) {
		this.trainerType = trainerType;
	}
	/**
	 * @return the trainerLevel
	 */
	public String getTrainerLevel() {
		return trainerLevel;
	}
	/**
	 * @param trainerLevel the trainerLevel to set
	 */
	public void setTrainerLevel(String trainerLevel) {
		this.trainerLevel = trainerLevel;
	}
	/**
	 * @return the certified
	 */
	public String getCertified() {
		return certified;
	}
	/**
	 * @param certified the certified to set
	 */
	public void setCertified(String certified) {
		this.certified = certified;
	}
	/**
     * 
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }
	/**
	 * @return the order
	 */
	public QueryOrder getOrder() {
		return order;
	}


}
